/**
 * @param {number[]} cookies
 * @param {number} k
 * @return {number}
 */
var distributeCookies = function(cookies, k) {
  let result = new Array(k).fill(0);
  cookies = cookies.sort((a, b) => b - a);
  for(let i = 0; i < cookies.length; i++) {
    const min = Math.min(...result);
    const index = result.indexOf(min);
    result[index] += cookies[i];
  }
  return result;
};
let cookies = [8,15,10,20,8], k = 2;
console.log(distributeCookies(cookies, k));
cookies = [6,1,3,2,2,4,1,2], k = 3;
console.log(distributeCookies(cookies, k));
cookies = [15,14,8,13,7,2,13,19], k = 3;
console.log(distributeCookies(cookies, k));
